battleEngine = {}
dofile (BaseData() .. "scripts\\battleData.lua")
dofile (BaseData() .. "scripts\\battleUIElements.lua")
dofile (BaseData() .. "scripts\\playersInfo.lua")
dofile (BaseData() .. "scripts\\enemiesInfo.lua")

battleEngine.StartBattle = function ()
	battleEngine.currentMode = ""
	battleUI.loadBattleUI()
end

battleEngine.Update = function ()
	
end

battleEngine.ActionsMenuReturn = function ()
	sel = GetMenu("ActionsMenu").selectedIndex
	if sel == 0 then
		battleEngine.currentMode = "selectMove"
	elseif sel == 1 then
		
	elseif sel == 2 then
		
	elseif sel == 3 then
		
	end
end

battleEngine.MouseEvent = function(t)
	mousePos = GetMousePos()
	if mousePos.X > 220 or mousePos.Y < 580 then
		if battleEngine.currentMode == "selectMove" then
			if t == MouseEvent("LeftDown") then
				battleEngine.MovePlayer(0)
			end
		end
	end
end

battleEngine.MovePlayer = function(playerIndex)
	originalPos = GetNPC(battleEngine.battleData.players[playerIndex].name).sprite.sceneNode.Position
	pos = GetMouseIntersect()
	if pos ~= nil then
		resultX = GetQuadCoordX(pos, battleEngine.battleData.hexSize)
		resultY = GetQuadCoordY(pos, battleEngine.battleData.hexSize)
		distance = GridDistance(resultX, resultY, GetQuadCoordX(originalPos, battleEngine.battleData.hexSize), GetQuadCoordY(originalPos, battleEngine.battleData.hexSize))
		if distance < 3 then
			battleEngine.battleData.players[playerIndex]:MoveTo(resultX, resultY, -8, distance * 500)
			battleEngine.currentMode = ""
		end
	end
end

battleEngine.Attack = function(playerIndex, enemyIndex)
	pos = GetMouseIntersect()
	pos = SumVector3(pos, Vector3(0,10,0))
	OverText("568", pos)
end

battleEngine.CalculateDamage = function(attack, shield)
	return attack / shield
end